package com.loginCheckMVC.dao.impl;

import com.loginCheckMVC.dao.UserDao;
import com.loginCheckMVC.druid.DruidUtils;
import com.loginCheckMVC.pojo.User;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class UserDaoImpl implements UserDao {

    private JdbcTemplate jdbcTemplate = new JdbcTemplate(DruidUtils.getDataSource());

    @Override
    public User findAllUser(String name, String password) {
        List<User> users = jdbcTemplate.query("select * from user", new BeanPropertyRowMapper<User>(User.class));
        for (User u : users) {
            if (u.getUsername().equals(name) && u.getPassword().equals(password)) {
                return u;
            }
        }
        return null;
    }
}
